/*
 * OnlineModeHandler.h
 *
 *  Created on: Oct 26, 2011
 *      Author: zwx
 */

#ifndef ONLINEMODEHANDLER_H_
#define ONLINEMODEHANDLER_H_
#include "../Query/BooleanParser.h"
#include "../Query/VSMParser.h"
#include "../Query/OkapiParser.h"
#include "../Processor/Processor.h"
#include "../Include/includes.h"
#include<string>

using namespace std;

struct query_info{
	char query[1024];
	char author[1024];
	char category[1024];
	int 	n_limit;		//the limit number of the return results
};


class OnlineModeHandler {
private:
	static const int MAX_LINE_SIZE = 1024;
	static const int MAX_POSTING_SIZE = 1048576;
public:
	OnlineModeHandler();
	virtual ~OnlineModeHandler();
	void handle();
	void segmentation(char*, struct query_info*);
	void extract_tag(char*, int, int, struct query_info*);
	list<struct doc>*  parse(struct query_info*);
	void filter_author(char* author, list<struct doc>* docs);
	void filter_category(char* category, list<struct doc>* docs);
	list<struct doc>* get_aut_postings(size_t id, size_t offset);
	list<struct doc>* get_cat_postings(size_t id, size_t offset);
	void doc_intersect(list<struct doc>* docs, list<struct doc>* fdoc);
	void extract_doc(list<struct doc>* adoc, char* line);
	bool is_wiki(char* name);
	void print_snippet(char* doc, list<struct doc>::iterator it);
};

#endif /* ONLINEMODEHANDLER_H_ */
